home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
524
/
524.xpi
/
chrome
/
mid.jar
/
content
/
midcontextmenu_ovr.js
< prev
next >
Wrap
Text File
|
2010-01-28
|
4KB
|
102 lines
var midcontextmenu = {
retries : 0,
mid_prefsvc : Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService),
onLoad: function() {
// initialization code
midcontextmenu.initialized = true;
midcontextmenu.strings = document.getElementById("midcontextmenu-strings");
document.getElementById("contentAreaContextMenu")
.addEventListener("popupshowing", function(e) { midcontextmenu.showContextMenu(e); }, false);
},
showContextMenu: function(event) {
var myitem = document.getElementById("context-midcontextmenu");
midcontextmenu.retries = 0;
if ((midcontextmenu.getTextSelected().length == 0) || !midcontextmenu.isContextEnabled()) {
myitem.hidden = true;
} else {
myitem.hidden = false;
}
},
onMenuItemCommand: function(e) {
function fibonacci(n) {
if (n==1 || n==2 ) {
return 1;
}
return fibonacci(n-1) + fibonacci(n-2);
}
var selText = midcontextmenu.getTextSelected();
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
windowMediator = windowMediator.QueryInterface(nsIWindowMediator);
var win = windowMediator.getMostRecentWindow("mid:main");
//var b = getBrowser(); in a tab
//if (b) {
// alert(b.contentWindow.location);
// win = b.contentWindow;
// win.domHelper.inputElement.value = selText;
// win.mid_mud.lookup.lookupWord();
// return;
//}
if (!win || !win.domHelper) {
midcontextmenu.retries = midcontextmenu.retries + 1;
if (midcontextmenu.retries > 10) {
midcontextmenu.retries = 0;
alert("mid not found :(");
return; // couldn't start mid
} else {
if (midcontextmenu.retries == 1) {
setTimeout(midtaskortoolsmenu.newMIDWindow,0); // arguments? miniwiew, selection
}
}
setTimeout(midcontextmenu.onMenuItemCommand,300 + fibonacci(midcontextmenu.retries)*100 )
return;
} else {
win.domHelper.inputElement.value = selText;
win.mid_mud.lookup.lookupWord();
win.focus();
}
midcontextmenu.retries = 0;
},
getTextSelected: function() {
var selection = "";
var node = document.popupNode;
var focusedWindow = new XPCNativeWrapper(document.commandDispatcher.focusedWindow, 'document', 'getSelection()');
if ((node instanceof HTMLTextAreaElement) || ((node instanceof HTMLInputElement) && (node.type == "text"))) {
selection = node.value.substring(node.selectionStart, node.selectionEnd);
} else {
selection = focusedWindow.getSelection().toString();
}
return selection;
},
isContextEnabled : function() {
if (midcontextmenu.mid_prefsvc.getPrefType("extensions.mid.menus.sendfromcontext") == midcontextmenu.mid_prefsvc.PREF_BOOL) {
if (midcontextmenu.mid_prefsvc.getBoolPref("extensions.mid.menus.sendfromcontext")) {
return true;
}
}
return false;
}
};
window.addEventListener("load", function(e) { midcontextmenu.onLoad(e); }, false);